package com.wh.beans.custom;


import com.legend.utils.StringUtils;
import com.wh.model.CustomField;

import java.text.MessageFormat;

public class Textarea implements ICustomLabel {

	@Override
	public String getCustomLabel(CustomField field, LabelType type) {
		String label = "", template = "";
		String fieldLittleName = StringUtils.getFieldLittleCamel(field.getFieldDbName());
		String fieldBigName = StringUtils.getFieldBigCamel(field.getFieldDbName());
		Float width = field.getInputWidth() == null ? 100 : field.getInputWidth();
		Integer height=field.getInputHeight()==null?100:field.getInputHeight();
		StringBuffer s;
		switch (type) {
		case add:
			boolean notEmpty = (field.getInputProperty() & 8) == 8;
			s = new StringBuffer();
			s.append(MessageFormat
					.format("<textarea id=\"txt{0}\" class=\"easyui-validatebox\" name=\"{1}\" style=\"width:{2}px;height:{4}px\" data-options=\"required:{3}\"></textarea>",
                            fieldBigName, fieldLittleName, width, notEmpty, height));
			label = s.toString();
			break;
		case edit:
			notEmpty = (field.getInputProperty() & 8) == 8;
			s = new StringBuffer();
			s.append(MessageFormat
					.format("<textarea id=\"txt{0}\" class=\"easyui-validatebox\" name=\"{1}\" style=\"width:{2}px;height:{4}px\" data-options=\"required:{3}\">$'{'info.data.{1}'}'</textarea>",
							fieldBigName, fieldLittleName, width, notEmpty, height));
			label = s.toString();
			break;
		case view:
			template = "$'{'info.data.{0}'}'";
			label = MessageFormat.format(template, fieldLittleName);
			break;
		default:
			break;
		}
		return label;
	}

}
